-
Notifications
You must be signed in to change notification settings - Fork 411
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ddl: Fix rename partitioned table is not atomic #9133
ddl: Fix rename partitioned table is not atomic #9133
Conversation
6d98b3a
to
8fc127f
Compare
PR needs rebase. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
8fc127f
to
07f9881
Compare
dd77843
to
fbefbd3
Compare
b63bfb2
to
9342a3a
Compare
dbms/src/Debug/MockTiDB.cpp
Outdated
const String & new_database_name, | ||
const String & new_table_name) | ||
{ | ||
std::lock_guard lock(tables_mutex); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use scoped_lock
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
auto opt_tbl_id = SchemaNameMapper::tryGetTableID(table_name); | ||
if (!opt_tbl_id) | ||
{ | ||
LOG_WARNING( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In what case could this happen?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cases under "tests/delta-merge-test" may create table with the given table_name rather that "t_${table_id}"
database_id, | ||
*opt_tbl_id, | ||
new_database_id); | ||
auto managed_storage = std::dynamic_pointer_cast<IManageableStorage>(tbl_iter->table()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also protect the cast?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added
Co-authored-by: jinhelin <[email protected]>
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: JinheLin, Lloyd-Pottiger The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
[LGTM Timeline notifier]Timeline:
|
In response to a cherrypick label: new pull request created to branch |
Signed-off-by: ti-chi-bot <[email protected]>
In response to a cherrypick label: new pull request created to branch |
close #9132 Signed-off-by: ti-chi-bot <[email protected]> Co-authored-by: JaySon <[email protected]>
close #9132 Co-authored-by: JaySon-Huang <[email protected]> Co-authored-by: JaySon <[email protected]>
What problem does this PR solve?
Issue Number: close #9132
Problem Summary:
In the previous implementation, when running
RENAME
for a partitioned table, it will skip renaming the following partitions if one of the IStorage instance does not exist.tiflash/dbms/src/TiDB/Schema/SchemaBuilder.cpp
Lines 667 to 691 in 73929ad
That work well on the versions before v7.2. But after DDL framework refactor since v7.2, there could be a chance that the IStorage instance is not created.
If there are "p1, p2, p3" for a partitioned table, but "p2" is empty. Then the IStorage instance of "p2" is not created. When we need to rename the partitioned table to another database, it will make that "p1" is renamed to the new database, but "p3" remain in the old database. This cause inconsistency.
What is changed and how it works?
applyRenameLogicalTable
will continue the rename for remaining partitions even if it happen to a partition that does not haveIStorage
instanceapplyRenameLogicalTable
, making some partitions is in the old database while some is in the new database. After restart,syncAllSchema
will calltryFixPartitionsBelongingDatabase
and check whether there are any partitions that does not belong to the database on disk. If so, rename the partition table to the correct database.Check List
Tests
Side effects
Documentation
Release note